package com.koko.controller;

import com.koko.game.dto.GamePriceDTO;
import com.koko.game.entity.GamePrice;
import com.koko.result.Result;
import com.koko.service.GamePriceService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/game")
public class GamePriceController {
    @Autowired
    private GamePriceService gamePriceService;

    // TODO 游戏价格优惠倒计时业务
    @PutMapping("/admin/price")
    @CacheEvict(value = "gameCache", allEntries = true)
    public Result<String> updateGamePrice(@RequestBody GamePriceDTO gamePriceDTO) {
        gamePriceService.update(gamePriceDTO);
        return Result.success();
    }

    @PostMapping("/admin/price")
    @CacheEvict(value = "gameCache", allEntries = true)
    public Result<String> addGamePrice(@RequestBody GamePriceDTO gamePriceDTO) {
        GamePrice gamePrice = new GamePrice();
        BeanUtils.copyProperties(gamePriceDTO, gamePrice);
        gamePriceService.save(gamePrice);
        return Result.success();
    }
}
